<?php

namespace app\api\controller;

use app\BaseController;
use app\common\business\Sms as SmsBus;
class Sms extends BaseController
{
    public function code()
    {
        $phoneNumber = input("param.phone_number", '', 'trim');
        if (empty($phoneNumber)) {
            return false;
        }

        $data = [
            'phone_number' => $phoneNumber
        ];

        try {
            validate(\app\api\validate\User::class)->scene('send_code')->check($data);
        } catch (\think\exception\ValidateException $e) {
            return show(config("status.error"), $e->getError());
        }

        // 调用business层数据
        if (SmsBus::sendCode($phoneNumber, config("aliyun.code_len"), $type = 'ali')) {
            return show(config("status.success"), "发送验证码成功");
        }
        return show(config("status.error"), "发送验证码失败");
    }
}